// pages/farmTool/farmTool.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    option1:[
      {text:'全部',value:0},
      {text:'出售',value:1},
      {text:'租借',value:2}
    ],
    toolList:[],
     tabs:['全部','售卖','出租'],
     current:0,
      value3:'sort',
      value4:0,
      value1:0,
      value2:'a',
      ani1:'',
      ani2:'',
      ani3:'',
      bottom:false
  },
  getData(num,page){
    var index2 = this.data.current;
    var type = '';
    if(index2 != 0){
      type = this.data.tabs[index2];
    }
      var that = this;
      wx.cloud.callFunction({
          name: 'getTool',
          // 传给云函数的参数
          data:{
              num:num,
              page:page,
              type:type
          }
        }).then(res => {
            var oldList = that.data.toolList;
            var newList = oldList.concat(res.result.data);
            that.setData({
                toolList : newList
            })
          }).catch(console.error)
  },
  onLoad: function (options) {
      this.getData(6,0);
     
  },
  price(){
   this.setData({
       value3:this.data.price[this.data.value4],
       value4:(this.data.value4+1)%2
   })
  },
  dropchange()
  {
      console.log(1);
  },
  OnClear()
  {
    this.setData({
      value1:0,
      value2:'a'
    })
  },
  Search(){
    wx.navigateTo({
      url: '/pages/search/search',
    })
  },

  tabSelect:function(e){
    var current = e.currentTarget.dataset.id
    this.setData({
      current:current,
      toolList:[]
    })
    this.getData(6,0);
  },
  onReachBottom: function () {
      this.setData({
          bottom:true
      })  
      var ani=wx.createAnimation({
        delay: 0,
        duration:400, 
        timingFunction:'ease'
      })
      ani.opacity(0.2).step().opacity(0.5).step().opacity(0.8).step().opacity(0.2).step().opacity(0.5).step().opacity(0.8).step().opacity(0.2).step().opacity(0.5).step().opacity(0.8).opacity(0.2).step().opacity(0.5).step().opacity(0.8).step().opacity(0.2).step().opacity(0.5).step().opacity(0.8).step().opacity(0.2).step().opacity(0.5).step().opacity(0.8).step().opacity(0.2).step().opacity(0.5).step().opacity(1).step();
      this.setData({
          ani1:ani.export()
      })
      ani=wx.createAnimation({
        delay: 0,
        duration:400, 
        timingFunction:'ease'
      })
      ani.opacity(0.5).step().opacity(0.8).step().opacity(0.2).step().opacity(0.5).step().opacity(0.8).step().opacity(0.2).step().opacity(0.5).step().opacity(0.8).step().opacity(0.2).step().opacity(0.5).step().opacity(0.8).step().opacity(0.2).step().opacity(0.5).step().opacity(0.8).step().opacity(0.2).step().opacity(0.5).step().opacity(0.8).step().opacity(0.2).step().opacity(0.5).step().opacity(0.8).step().opacity(1).step();
      this.setData({
          ani2:ani.export()
      })
      ani=wx.createAnimation({
        delay: 0,
        duration:400, 
        timingFunction:'ease'
      })
      ani.opacity(0.8).step().opacity(0.2).step().opacity(0.5).step().opacity(0.8).step().opacity(0.2).step().opacity(0.5).step().opacity(0.8).step().opacity(0.2).step().opacity(0.5).step().opacity(0.8).step().opacity(0.2).step().opacity(0.5).step().opacity(0.8).step().opacity(0.2).step().opacity(0.5).step().opacity(0.8).step().opacity(0.2).step().opacity(0.5).step().opacity(0.8).step().opacity(0.2).step().opacity(1).step();
      this.setData({
          ani3:ani.export()
      })
    var page = this.data.toolList.length
    this.getData(6,page)
  
    this.setData({
        bottom:false
    })
},
  onPullDownRefresh:function () {
    wx.showLoading({
      title: '刷新中',
    })
 setTimeout(()=>{ wx.stopPullDownRefresh({
 success: (res) => {}})
 wx.hideLoading({
   success: (res) => {},
 })},1000)  }

})